//
//  SheetItemViews.swift
//  AG
//
//  Created by zhuxuhong on 2020/10/23.
//  Copyright © 2020 3moon. All rights reserved.
//

import UIKit

class SheetSeparatorView: CollectionReusableView {
    override func didInit() {
        backgroundColor = R.color.black20()
    }
}

class SheetItemCell: CollectionViewCell {
    override var needsHighlightable: Bool {
        return true
    }
}

enum SheetItemStyle {
    case `default`
    case primary
    case cancel
    case destructive
    var tintColor: UIColor? {
        switch self {
        case .default:
            return R.color.black()
        case .cancel:
            return R.color.black40()
        case .destructive:
            return R.color.red()
        case .primary:
            return R.color.bb9957()
        }
    }
}

class SheetIconTextCell: SheetTextCell {
    struct Data {
        var icon: UIImage?
        var title: String?
    }
    lazy var iconIV: ImageView = {
        let v = ImageView(frame: .init(origin: .zero, size: .with(both: 22)))
        v.renderColor = Color.white
        return v
    }()
    
    override func didInit() {
        contentView.addSubview(iconIV)
        contentView.addSubview(titleLb)
        iconIV.snp.makeConstraints{
            $0.trailing.equalTo(titleLb.snp.leading).offset(-10)
            $0.width.height.equalTo(iconIV.width)
            $0.centerY.equalToSuperview()
        }
        titleLb.snp.makeConstraints{
            $0.centerX.equalToSuperview().offset(16)
            $0.centerY.equalToSuperview()
        }
        
        addBorder()
    }
    
    override func bwListItemViewConfigure(_ data: Any?, indexPath: IndexPath) {
        guard let data = data as? Data else {
            return
        }
        iconIV.image = data.icon
        super.bwListItemViewConfigure(SheetTextCell.Data(title: data.title), indexPath: indexPath)
    }
}

class SheetTextCell: SheetItemCell {
    struct Data {
        var title: String?
        var style: SheetItemStyle = .default
        init(title: String?, style: SheetItemStyle = .default) {
            self.title = title
            self.style = style
        }
    }
    
    lazy var titleLb: UILabel = {
        let v = UILabel()
        v.text = "Text"
        v.font = Font.System.p16
        v.textColor = R.color.black()
        v.sizeToFit()
        return v
    }()
    
    override func didInit() {
        super.didInit()
        
        contentView.addSubview(titleLb)
        titleLb.snp.makeConstraints {
            $0.center.equalTo(contentView)
        }
        addBorder()
    }
    
    override func bwListItemViewConfigure(_ data: Any?, indexPath: IndexPath) {
        guard let data = data as? Data else {
            return
        }
        titleLb.text = data.title
        titleLb.textColor = data.style.tintColor
    }
}

class SheetTitleView: CollectionReusableView {
    
    lazy var titleLb: UILabel = {
        let v = UILabel()
        v.text = "标题"
        v.font = Font.System.p14
        v.textColor = R.color.black40()
        v.sizeToFit()
        return v
    }()
    
    override func didInit() {
        super.didInit()
        
        addSubview(titleLb)
        titleLb.snp.makeConstraints {
            $0.center.equalToSuperview()
        }
        addBorder()
    }
    override func bwListItemViewConfigure(_ data: Any?, indexPath: IndexPath) {
        titleLb.text = data as? String
    }
}


class SheetCancelCell: SheetTextCell {
    override func didInit() {
        super.didInit()
        
        titleLb.font = Font.System.p16.medium
    }
    
    override func bwListItemViewConfigure(_ data: Any?, indexPath: IndexPath) {
        super.bwListItemViewConfigure(Data(title: "取消", style: .cancel), indexPath: indexPath)
    }
}
